package look4ss.aplicativo;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class ActivityAddNome extends AppCompatActivity {
    private Button botaoFinalizar;
    private ProgressDialog carregandoTela;
    private EditText definirNome;
    private SharedPreferences sharp;
    public FirebaseUser usuario = FirebaseAuth.getInstance().getCurrentUser();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_nome);

        if(usuario == null){
            startActivity(new Intent(ActivityAddNome.this, ActivityLogin.class));
            finish();
        }
        carregandoTela = new ProgressDialog(this);
        definirNome = findViewById(R.id.definirNome);
        botaoFinalizar = findViewById(R.id.botaoConcluir);

        botaoFinalizar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                personalizarConta();
                finish();
            }
        });
    }
    private void personalizarConta() {
        String nome = definirNome.getText().toString();

        if(!nome.equals("")) {
            carregandoTela.setMessage(getString(R.string.carregando));
            carregandoTela.show();

            sharp = getSharedPreferences("usuario", Context.MODE_PRIVATE);
            SharedPreferences.Editor edtr = sharp.edit();
            edtr.putString("nome", nome);
            edtr.apply();

            carregandoTela.dismiss();
            startActivity(new Intent(this, ActivityEnviar.class));
        }
        }
    }
